<?php

namespace app\common\job;

use app\admin\service\MemberMutedService;
use think\facade\Log;
use think\queue\Job;

/**
 * 用户禁言解除
 * Class MemberMutedExpiration
 * @package app\common\job
 */
class MemberMutedExpiration
{
    private MemberMutedService $memberMutedService;

    public function __construct(MemberMutedService $memberMutedService)
    {

        $this->memberMutedService = $memberMutedService;
    }

    /**
     * fire是消息队列默认调用的方法
     * @param Job $job 当前的任务对象
     * @param array|mixed $data 发布任务时自定义的数据
     */
    public function fire(Job $job, $data)
    {
        $id = $data['id'] ?? null;

        try {
            $this->memberMutedService->tryMutedExpiration($id);
        } catch (\Exception $exception) {
            Log::error('消费队列：' . $exception->getMessage());
        }

        $job->delete();
    }

}
